﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Gift.WebApp;
using Gift.Model;

namespace WebSite.admin.company
{
    public partial class companyMoney : BaseAdmin
    {
      
       

        string ParamentType
        {
            get
            {
                return Request.QueryString["type"];
            }
        }
        string Stype
        {
            get
            {
                return Request.QueryString["stype"];
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
              
                    if (Stype == "out")
                    {
                        base.ValidateLoginRule(Gift.Model.ENUM.ERule.CompanyMoneyOut);
                        this.lblType.Text = "出账";
                    }
                    else
                    {
                        base.ValidateLoginRule(Gift.Model.ENUM.ERule.CompanyMoneyIn);
                        this.lblType.Text = "入账";
                    }
             
                try
                {
                   
                    tbCompany oCompany;
                    oCompany = BaseFactory.theCompany.GetModel(int.Parse(Request.QueryString["id"]));
                    if (base.Administrator.CompanyId == oCompany.Id.ToString())
                    {
                        this.txtMoney.Enabled = false;
                        this.txtRemark.Enabled = false;
                        this.btnSubmit.Enabled = false;
                    }
                    this.lblCompanyName.Text = oCompany.Name;
                }
                catch
                {
                    base.Response.Write("<script language='javascript'>alert('非法操作！');window.location.href='companyMoneyList.aspx?type=" + ParamentType +"';</script>");
                }
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string sSQL = "insert into tbCompanyMoney(CompanyId,InMoney,OutMoney,OperateTime,AdminId,Remark) "
                         + " values({0},{1},{2},'{3}',{4},'{5}')";
            float inMoney = 0;
            float outMoney = 0;

            if(Request.QueryString["type"] == "out")
            {
                   outMoney = float.Parse(this.txtMoney.Text);
             
            }else
            {
                   inMoney = float.Parse(this.txtMoney.Text);
            }

            SQLAccess.DoSql(string.Format(sSQL,Request.QueryString["id"],inMoney,outMoney,DateTime.Now.ToString(),base.Administrator.AdminUserId,this.txtRemark.Text.Trim()));
            base.Response.Write("<script language='javascript'>alert('保存成功');window.location.href='companyMoneyList.aspx?type=" + ParamentType +"';</script>");
        }

     
      
    }
}